﻿using GBT.Tool.Core;
using Newtonsoft.Json.Linq;
using NLog;
using Persistence.Core;
using System;
using System.Data.SqlClient;

namespace QueryDataLogic.Core
{
    public class SystemSetting
    {
        private static Logger logger = LogManager.GetCurrentClassLogger();
        ConfigManage cm = new ConfigManage();
        QueryData qd = new QueryData();

        /// <summary>
        /// 获取系统配置信息
        /// </summary>
        /// <param name="districtID"></param>
        /// <returns></returns>
        public JObject GetSystemSetting(int districtID)
        {
            JObject joResult = new JObject();
            try
            {
                SqlCommand comm = new SqlCommand()
                {
                    CommandText = "select id,name,value from SystemSetting where districtID = @districtID "
                };

                comm.Parameters.AddWithValue("@districtID", districtID);
                JArray ja = qd.GetData(comm, "MealManage");

                if (ja.Count > 0)
                {
                    for (int index = 0; index < ja.Count; index++)
                    {
                        joResult[(string)ja[index]["name"]] = (string)ja[index]["value"];
                    }
                    joResult["SystemSetting"] = ja;
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                Console.Write(ex);
            }
            return joResult;
        }
    }
}
